package command

import (
	"errors"
	"strings"
	"time"

	"ssdevice/common/dto"
	"ssdevice/common/utils"
	"ssdevice/internal/device/models"
)

type TagInsertReq struct {
	Name string `json:"name" vd:"len($)>0"`
	dto.UserInfo
}

func (d *TagInsertReq) Generate(tag *models.SysTag) error {
	tag.Id = utils.SimpleUUID()
	tag.Name = strings.TrimSpace(d.Name)
	now := dto.LocalTime(time.Now())
	tag.CreateTime = &now
	tag.UpdateTime = &now
	return nil
}

type TagReq struct {
	Id  string   `json:"id" vd:"len($)>0"`
	Ids []string `json:"-"`
	dto.UserInfo
}

func (d *TagReq) Generate(tag *models.SysTag) error {
	if len(d.Id) == 0 {
		return errors.New("id is empty")
	}

	d.Ids = strings.Split(d.Id, ",")
	return nil
}

type TagDeviceReq struct {
	DevSn string `json:"devSn" vd:"len($)>0"`
	TagId string `json:"tagId" vd:"len($)>0"`
	dto.UserInfo
}
